/*
 * TransitPathModificationAction.java
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.rtemaster.actions;

import org.fpdev.core.data.LegacyDB;
import org.fpdev.core.transit.SubRoute;
import org.fpdev.core.transit.TransitPath;
import org.fpdev.apps.rtemaster.RouteMaster;
import org.fpdev.apps.rtemaster.gui.map.MapDrawItems;

/**
 *
 * @author demory
 */
public abstract class TransitPathModificationAction implements ACAction {

  protected SubRoute sub_;
  private TransitPath tpath_;

  public TransitPathModificationAction(SubRoute sub) {
    sub_ = sub;
  }

  public void updateDB(LegacyDB db) {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public boolean doAction(RouteMaster ac) {
    TransitPath path = sub_.getPath();
    //System.out.println("initial path len="+path.linkCount());
    tpath_ = path.createCopy(ac.getEngine(), sub_, false);

    if (!modifyTransitPath(ac)) {
      return false;
    }

    ac.getGUI().getRouteSelectionPanel().updateSubs();
    ac.getRouteOps().getRoutes().changesMade();

    //System.out.println("final path len="+path.linkCount());

    return true;
  }

  protected abstract boolean modifyTransitPath(RouteMaster ac);

  public boolean undoAction(RouteMaster ac) {
    sub_.setPath(tpath_);
    //System.out.println("restoring path len="+tpath_.linkCount());
    ac.getGUI().getMapPanel().getDrawItems().addItem(MapDrawItems.RTE_TRANSIT_PATH, tpath_, "r", 20);
    ac.getGUI().getRouteSelectionPanel().updateSubs();
    return true;
  }

  //public String getName();
}
